package com.Qinmeiwei.web.controller;

import org.springframework.ui.ModelMap;
import org.springframework.web.servlet.ModelAndView;

import com.Qinmeiwei.web.util.JsonUtil;

public class BaseController {
	
	private static final String AJAX_JSON_RESULT = "ajaxJSONResult";
	
	/**
	 * 返回JSON视图
	 * 
	 * 用法：return setJson(obj);
	 * @param obj
	 * @return
	 */
	public static ModelAndView setJson(Object obj) {
		ModelMap map = new ModelMap();
		map.put("json", obj == null ? null : JsonUtil.toJson(obj));
		ModelAndView mv = new ModelAndView();
		mv.addAllObjects(map);
		mv.setViewName(AJAX_JSON_RESULT);
		return mv;
	}

}
